package com.treeHole.treeHoleServer.utils;


import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    private static String signKey="HUST_TreeHole";
    private static Long expire=432000000L;

    /**
     * 生成令牌
     */
    public static String generateJwt(Map<String, Object> claims) {
        return Jwts.builder()
                        .addClaims(claims)//设置有效载荷
                .signWith(SignatureAlgorithm.HS256,signKey)//头部签名算法
                .setExpiration(new Date(System.currentTimeMillis()+expire))//设置过期时间
                .compact();
    }
    public static Claims parseJwt(String jwt) {
        return Jwts.parser()
                .setSigningKey(signKey)
                .parseClaimsJws(jwt).getBody();
    }


}
